/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package session;


import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ejb.EJB;

import entity.Contract;

/**
 *
 * @author Declan
 */
@Stateless
public class ContractFacade extends AbstractFacade<Contract> {
    @PersistenceContext(unitName = "PhoneShopPU")
    private EntityManager em;

    @EJB
    private NetworkFacade networkFacade;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ContractFacade() {
        super(Contract.class);
        networkFacade = new NetworkFacade();
    }
    
    @Override
    public void create(Contract entity) {
       
        // If Network does not exist, create it
        if(entity.getNetwork().getId() == null)
            networkFacade.create(entity.getNetwork());
        em.persist(entity);

    }

    @Override
    public void edit(Contract entity) {
        // If Network does not exist, create it
        if(entity.getNetwork().getId() == null)
            networkFacade.create(entity.getNetwork());
        em.merge(entity);
        
   }
}
